<?php
$_GET['keyword'] = empty($_GET['keyword']) ? '' : trim($_GET['keyword']);
$_GET['userid'] = $__userinfo['userid'];
$oOrder = new Order();
$orderlist = $oOrder->get_list('*', $_GET, array('id' => 'DESC'));
if(!empty($orderlist)){
	$vars['list'] = array();
	foreach($orderlist['list'] as $orderinfo){
		
		$statename = '';
		$payment_statename = '';
		$delivery_statename = '';
		
		switch($orderinfo['state']){
			case '-2':
				$statename = '无效';
				break;
			case '-1':
				$statename = '已取消';
				break;
			case '0':
				$statename = '未确认';
				break;
			case '1':
				$statename = '已确认';
				break;
			case '2':
				$statename = '完成';
				break;
			case '3':
				$statename = '已评价';
				break;
		}
		
		switch($orderinfo['payment_state']){
			case '-1':
				$payment_statename = '付款失败';
				break;
			case '0':
				$payment_statename = '未付款';
				break;
			case '1':
				$payment_statename = '付款中';
				break;
			case '2':
				$payment_statename = '已付款';
				break;
		}
		
		switch($orderinfo['delivery_state']){
			case '0':
				$delivery_statename = '未发货';
				break;
			case '1':
				$delivery_statename = '配货中';
				break;
			case '2':
				$delivery_statename = '已发货';
				break;
			case '3':
				$delivery_statename = '已收货';
				break;
		}
		$orderinfo['statename'] = $statename;
		$orderinfo['payment_statename'] = $payment_statename;
		$orderinfo['delivery_statename'] = $delivery_statename;
		
		$orderinfo['addtime'] = ftime($orderinfo['addtime']);
		
		// 订单商品
		$goodslist = $oOrder->get_order_goods_all($orderinfo['sn'], $detail = true);
		foreach($goodslist as $key => $goods){
			if(empty($goods['goodsinfo']['filename'])){
				$goods['url'] = PUB_DIR.'goods/'.time_to_path($goods['goodsinfo']['addtime']).'/'.$goods['goodsinfo']['id'].'.html';
			}else{
				$goods['url'] = PUB_DIR.'goods/'.$goods['goodsinfo']['filename'].'.html';
			}
			$goodslist[$key] = $goods;
		}
		$orderinfo['goodslist'] = $goodslist;
		
		// 收货人信息
		$orderinfo['address'] = $oOrder->get_order_address($orderinfo['sn']);
		$orderinfo['address']['besttime_text'] = Statics::$delivery_date_arr[$orderinfo['address']['besttime']];
		
		// 高亮关键词
		//if(!empty($_GET['keyword'])){
			$orderinfo['_hl_sn'] = highlight_word($orderinfo['sn'], $_GET['keyword']);
			$orderinfo['_hl_consignee'] = highlight_word($orderinfo['consignee'], $_GET['keyword']);
		//} 
		$vars['list'][] = $orderinfo;
	}
	
	$vars['pagelist'] = $orderlist['pagelist'];
}
//print_r($orderlist);
?>